#include "LoopSave.h"

#include <QFile>
#include <QTextStream>

using namespace std;

LoopSave::LoopSave()
{

}

LoopSave::~LoopSave()
{

}

int LoopSave::save(Clock clock,Output output,Pulse *field,MultiLayer multiLayer)
{
  QFile file(output.getFileName());
  QTextStream myfile(&file);
  int layerNumber=multiLayer.getSolveLayer();
  file.open(QIODevice::Append);
  myfile<<field->getLevel(clock.getTimeStamp())<<"\t";
  myfile<<multiLayer[layerNumber].getMag().getX()<<"\t";
  myfile<<multiLayer[layerNumber].getMag().getY()<<"\t";
  myfile<<multiLayer[layerNumber].getMag().getZ()<<"\t";
  myfile<<"\n";
  file.close();
  return 0;
}

int LoopSave::initSave(Output output)
{
  QFile file(output.getFileName());
  QTextStream myfile(&file);
  file.open(QIODevice::Append);
  myfile<<"field\t";
  myfile<<"mx\t";
  myfile<<"my\t";
  myfile<<"mz\t";
  myfile<<"\n";
  file.close();
  return 0;
}
